/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import classes.Auction;
import classes.AuctionDAO;
import classes.Bid;
import classes.ProductType;
import classes.User;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Ndnam
 */
public class Test extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        AuctionDAO auctionDAO = new AuctionDAO();
//        try {
//            auctionDAO.insertUser(new User(2, "abcxzy", "Tam", "Nguyen", "tamnt@gmail.com", "Up", "normal", "Ha Noi", "Cambodia", "2", "1111", "America", "0123456789"));
//            auctionDAO.insertProductType(new ProductType(1, "Mobile Phone"));
//            auctionDAO.insertAuction(new Auction(1, 3, 1, 1, "iPhone 5", 500, 750, "20:00", "2012-3-4", "20:00" , "2012-3-5", "Sold", 4, 3, "flickr.com", "youtube.com"));
//            auctionDAO.insertBid(new Bid(1,6,1,500,"cwinner","2013-7-20 15:00:30"));
//            out.println("Insert OK"); 
//        } catch (SQLException ex) { out.println(ex.getMessage());  }
        
        try {
//            auctionDAO.updateAuction(new Auction(6, 3, 1, 1, "iPhone 5S", 500, 750, "20:00", "2012-3-4", "20:00", "2012-3-5", "Sold", 4, 5,"www.flickr.com","youtube.com"));
            auctionDAO.updateBid(new Bid(6,6,1,500,"Winner","2013-7-20 15:40:30"));
//            auctionDAO.updateProductType(new ProductType(1, "Smart Phone"));
//            auctionDAO.updateUser(new User(2, "abcxzy", "Tam", "Nguyen", "tamnt@gmail.com", "Up", "normal", "Ha Noi", "Cambodia", "2", "11111", "America", "0123456789"));
//            out.println("Update OK");
        } catch (SQLException ex)  { out.println(ex.getMessage());  }
        
//        try {
//            auctionDAO.deleteBid(5);
//            auctionDAO.deleteAuction(5);
//            auctionDAO.deleteProductType(1);
//            auctionDAO.deleteUser(2);
//            out.println("Deleted");
//        } catch (SQLException ex) { out.println(ex.getMessage());  }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
